package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.CartBean;
import com.scoy.honeymei.bean.GoodsOrderBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description: 订单详情adapter
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class OrderDeAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<CartBean> datalist;

    public OrderDeAdapter(Context context, ArrayList<CartBean> datalist) {
        this.context = context;
        this.datalist = datalist;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_order_detail, parent, false);
        return new OrderDeHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        OrderDeHolder orderHolder = (OrderDeHolder) holder;
        CartBean cartBean = datalist.get(position);
        orderHolder.icaShopnameTv.setText(cartBean.getShopname());

        List<GoodsOrderBean> goodsList = cartBean.getGoodsList();

        ArrayList<GoodsOrderBean> dataItemList = new ArrayList<>();
        dataItemList.addAll(goodsList);
        OrderItemAdapter orderItemAdapter = new OrderItemAdapter(context, dataItemList, 1);
        orderHolder.icaRv.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
        orderHolder.icaRv.setAdapter(orderItemAdapter);


    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }


    class OrderDeHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ica_shopname_tv)
        TextView icaShopnameTv;
        @BindView(R.id.ica_rv)
        RecyclerView icaRv;

        OrderDeHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
